const tabs = {
  state: {
    tabList: [],
    tab: {}
  },
  //异步操作
  actions: {

  },
  //同步操作
  mutations: {
    ADD_TAB: (state, action) =>{
      state.tab = action;
      //已存在标签
      if (state.tabList.some(item => item.meta.tabId === action.meta.tabId )) return;
      //插入标签
      state.tabList.push(action)
    },
    DEL_TAB: (state, action) =>{
      state.tabList = state.tabList.filter(item => item.meta.tabId !== action);
    },
    DEL_ALL_TAB: state =>{
      state.tabList = []
    },
    DEL_OTHER_TAB: (state,action) =>{
      state.tabList =  state.tabList.filter(item => item.meta.tabId === action);
    },
    SET_TAB_LIST: (state,list) =>{
      state.tabList = list;
    }
  },
  getters: {
    getTabList: state => state.tabList,
    getTab: state => state.tab,
  }
}
export default tabs;
